package com.cssw.fyzb.core.dao.video;

import com.cssw.fyzb.core.model.dodb.CmfVideoHotDef;
import com.ydn.dbframe.plugin.activerecord.Page;
import com.ydn.dbframe.plugin.activerecord.parse.SqlParse;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Date;

/**
 * @author YangYiQun
 */
@Repository
public class VideoHotDefDaoImpl implements VideoHotDefDao {

    @Override
    public CmfVideoHotDef findById(Long hotId) {
        return CmfVideoHotDef.dao.findById(hotId);
    }

    @Override
    public List<CmfVideoHotDef> list() {
        String sql = "select * from cmf_video_hot_def where state = '1'";
        return CmfVideoHotDef.dao.find(sql);
    }

    @Override
    public Page<CmfVideoHotDef> adminList(Integer page, Integer limit, Map param) {
        SqlParse sqlParse = new SqlParse(param);
        sqlParse.addSQL(" select * from cmf_video_hot_def where state = '1' ");
        return CmfVideoHotDef.dao.paginate(page,limit,sqlParse);
    }

    @Override
    public Boolean save(Integer hotValue, String hotName, BigDecimal price, Integer hotTime, String hotOprName, String hotOprCode, Long sysOperId) {
        CmfVideoHotDef cmfVideoHotDef = new CmfVideoHotDef();
        cmfVideoHotDef.setHotValue(hotValue);
        cmfVideoHotDef.setHotName(hotName);
        cmfVideoHotDef.setPrice(price);
        cmfVideoHotDef.setHotTime(hotTime);
        cmfVideoHotDef.setHotOprName(hotOprName);
        cmfVideoHotDef.setHotOprCode(hotOprCode);
        cmfVideoHotDef.setCreateOperId(sysOperId);
        cmfVideoHotDef.setCreateTime(new Date());
        return cmfVideoHotDef.save();
    }

    @Override
    public Boolean update(Long hotId, Integer hotValue, String hotName, BigDecimal price, Integer hotTime, String hotOprName, String hotOprCode, Long sysOperId){
        CmfVideoHotDef cmfVideoHotDef = new CmfVideoHotDef();
        cmfVideoHotDef.setHotId(hotId);
        cmfVideoHotDef.setHotValue(hotValue);
        cmfVideoHotDef.setHotName(hotName);
        cmfVideoHotDef.setPrice(price);
        cmfVideoHotDef.setHotTime(hotTime);
        cmfVideoHotDef.setHotOprName(hotOprName);
        cmfVideoHotDef.setHotOprCode(hotOprCode);
        cmfVideoHotDef.setUpdateOperId(sysOperId);
        cmfVideoHotDef.setUpdateTime(new Date());
        return cmfVideoHotDef.update();
    }

    @Override
    public Boolean delete(Long hotId, Long sysOperId){
        CmfVideoHotDef cmfVideoHotDef = new CmfVideoHotDef();
        cmfVideoHotDef.setHotId(hotId);
        cmfVideoHotDef.setState("0");
        cmfVideoHotDef.setUpdateOperId(sysOperId);
        cmfVideoHotDef.setUpdateTime(new Date());
        return cmfVideoHotDef.update();
    }
}
